/*********************************************************************
 *                                                                    *
 *                SEGGER Microcontroller GmbH & Co. KG                *
 *        Solutions for real time microcontroller applications        *
 *                                                                    *
 **********************************************************************
 *                                                                    *
 * C-file generated by:                                               *
 *                                                                    *
 *        GUI_Builder for emWin version 5.22                          *
 *        Compiled Jul  4 2013, 15:16:01                              *
 *        (c) 2013 Segger Microcontroller GmbH & Co. KG               *
 *                                                                    *
 **********************************************************************
 *                                                                    *
 *        Internet: www.segger.com  Support: support@segger.com       *
 *                                                                    *
 **********************************************************************
 */

// USER START (Optionally insert additional includes)
#include "stdint.h"
// USER END

#include "DIALOG.h"

/*********************************************************************
 *
 *       Defines
 *
 **********************************************************************
 */
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_BUTTON_2 (GUI_ID_USER + 0x03)
#define ID_BUTTON_3 (GUI_ID_USER + 0x04)
#define ID_BUTTON_4 (GUI_ID_USER + 0x05)
#define ID_BUTTON_5 (GUI_ID_USER + 0x06)
#define ID_BUTTON_6 (GUI_ID_USER + 0x07)
#define ID_BUTTON_7 (GUI_ID_USER + 0x08)
#define ID_BUTTON_8 (GUI_ID_USER + 0x09)
#define ID_BUTTON_9 (GUI_ID_USER + 0x0A)
#define ID_BUTTON_10 (GUI_ID_USER + 0x0B)
#define ID_BUTTON_11 (GUI_ID_USER + 0x0C)
#define ID_BUTTON_12 (GUI_ID_USER + 0x0D)
#define ID_BUTTON_13 (GUI_ID_USER + 0x0E)
#define ID_BUTTON_14 (GUI_ID_USER + 0x0F)
#define ID_BUTTON_15 (GUI_ID_USER + 0x10)
#define ID_EDIT_0 (GUI_ID_USER + 0x11)

// USER START (Optionally insert additional defines)
#define ID_TIMER_0 (GUI_ID_USER + 0x70)
// USER END

/*********************************************************************
 *
 *       Static data
 *
 **********************************************************************
 */

// USER START (Optionally insert additional static data)

// USER END

/*********************************************************************
 *
 *       _aDialogCreate
 */
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    {FRAMEWIN_CreateIndirect, "Framewin2", ID_FRAMEWIN_0, 0, 0, 800, 480, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_0", ID_BUTTON_0, 111, 265, 72, 18, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_1", ID_BUTTON_1, 106, 219, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_2", ID_BUTTON_2, 207, 219, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_3", ID_BUTTON_3, 305, 222, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_4", ID_BUTTON_4, 105, 178, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_5", ID_BUTTON_5, 207, 180, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_6", ID_BUTTON_6, 307, 183, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_7", ID_BUTTON_7, 104, 140, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_8", ID_BUTTON_8, 208, 140, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_9", ID_BUTTON_9, 303, 141, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_jia", ID_BUTTON_10, 403, 144, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_jian", ID_BUTTON_11, 406, 184, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_cheng", ID_BUTTON_12, 401, 222, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_chu", ID_BUTTON_13, 407, 260, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_deng", ID_BUTTON_14, 306, 260, 80, 20, 0, 0x0, 0},
    {BUTTON_CreateIndirect, "Button_clean", ID_BUTTON_15, 204, 260, 80, 20, 0, 0x0, 0},
    {EDIT_CreateIndirect, "Edit", ID_EDIT_0, 108, 80, 359, 42, 0, 0x64, 0},
    // USER START (Optionally insert additional widgets)
    // USER END
};

/*********************************************************************
 *
 *       Static code
 *
 **********************************************************************
 */

// USER START (Optionally insert additional static code)
static void task(int8_t *state)
{
}
// USER END

/*********************************************************************
 *
 *       _cbDialog
 */
static void _cbDialog(WM_MESSAGE *pMsg)
{
  WM_HWIN hItem;
  int NCode;
  int Id;
  // USER START (Optionally insert additional variables)
  static int32_t res = 0;
  static int32_t para1 = 0;
  static int32_t para2 = 0;
  static int8_t cal_flag = 0;
  static int8_t eql_flag = 0;
  static int8_t state1 = 0;
  static int8_t count1 = 0;
  int8_t buffer[32];
  // USER END

  switch (pMsg->MsgId)
  {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Button_0'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetText(hItem, "0");
    //
    // Initialization of 'Button_1'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    BUTTON_SetText(hItem, "1");
    //
    // Initialization of 'Button_2'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
    BUTTON_SetText(hItem, "2");
    //
    // Initialization of 'Button_3'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
    BUTTON_SetText(hItem, "3");
    //
    // Initialization of 'Button_4'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_4);
    BUTTON_SetText(hItem, "4");
    //
    // Initialization of 'Button_5'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);
    BUTTON_SetText(hItem, "5");
    //
    // Initialization of 'Button_6'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_6);
    BUTTON_SetText(hItem, "6");
    //
    // Initialization of 'Button_7'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_7);
    BUTTON_SetText(hItem, "7");
    //
    // Initialization of 'Button_8'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_8);
    BUTTON_SetText(hItem, "8");
    //
    // Initialization of 'Button_9'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_9);
    BUTTON_SetText(hItem, "9");
    //
    // Initialization of 'Button_jia'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_10);
    BUTTON_SetText(hItem, "+");
    //
    // Initialization of 'Button_jian'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_11);
    BUTTON_SetText(hItem, "-");
    //
    // Initialization of 'Button_cheng'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_12);
    BUTTON_SetText(hItem, "*");
    //
    // Initialization of 'Button_chu'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_13);
    BUTTON_SetText(hItem, "/");
    //
    // Initialization of 'Button_deng'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_14);
    BUTTON_SetText(hItem, "=");
    //
    // Initialization of 'Button_clean'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_15);
    BUTTON_SetText(hItem, "c");
    //
    // Initialization of 'Edit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
    EDIT_SetText(hItem, "0");
    EDIT_SetTextColor(hItem, EDIT_CI_ENABLED, 0x00FF0000);
    EDIT_SetFont(hItem, GUI_FONT_20_ASCII);
    EDIT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER);
    // USER START (Optionally insert additional code for further widget initialization)
    WM_CreateTimer(WM_GetClientWindow(pMsg->hWin), ID_TIMER_0, 100, 0);
    state1 = 0;
    // USER END
    break;
  case WM_NOTIFY_PARENT:
    Id = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (Id)
    {
    case ID_BUTTON_0: // Notifications sent by 'Button_0'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_1: // Notifications sent by 'Button_1'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 1;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_2: // Notifications sent by 'Button_2'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 2;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_3: // Notifications sent by 'Button_3'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 3;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_4: // Notifications sent by 'Button_4'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 4;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_5: // Notifications sent by 'Button_5'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 5;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_6: // Notifications sent by 'Button_6'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 6;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_7: // Notifications sent by 'Button_7'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 7;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_8: // Notifications sent by 'Button_8'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 8;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_9: // Notifications sent by 'Button_9'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        res = res * 10 + 9;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_10: // Notifications sent by 'Button_jia'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        cal_flag = 1;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_11: // Notifications sent by 'Button_jian'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        cal_flag = 2;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_12: // Notifications sent by 'Button_cheng'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        cal_flag = 3;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_13: // Notifications sent by 'Button_chu'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        cal_flag = 4;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_14: // Notifications sent by 'Button_deng'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        eql_flag = 1;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_BUTTON_15: // Notifications sent by 'Button_clean'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        state1 = 0;
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
    case ID_EDIT_0: // Notifications sent by 'Edit'
      switch (NCode)
      {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        GUI_EndDialog(pMsg->hWin, 0);
        CreateFramewin();
        // USER END
        break;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
        // USER END
        break;
        // USER START (Optionally insert additional code for further notification handling)
        // USER END
      }
      break;
      // USER START (Optionally insert additional code for further Ids)
      // USER END
    }
    break;
    // USER START (Optionally insert additional message handling)
  case WM_TIMER:
    WM_RestartTimer(pMsg->Data.v, 10);

    count1++;
    if (count1 >= 10)
    {
      count1=0;
			switch (state1)
      {
      case (0):
      {
        res = 0;
        para1 = 0;
        para2 = 0;
        cal_flag = 0;
        eql_flag = 0;
        state1 = 1;
      }
      break;
      case (1):
      {
        sprintf(buffer, "%d", res);
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
        EDIT_SetText(hItem, buffer);
        if (cal_flag != 0)
        {
          para1 = res;
					res = 0;
          state1 = 2;
        }
      }
      break;
      case (2):
      {
        sprintf(buffer, "%d", res);
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
        EDIT_SetText(hItem, buffer);
        if (eql_flag != 0)
        {
          para2 = res;
          state1 = 3;
        }
      }
      break;
      case (3):
      {
        if (cal_flag == 1)
        {
          res = para1 + para2;
        }
        else if (cal_flag == 2)
        {
          res = para1 - para2;
        }
        else if (cal_flag == 3)
        {
          res = para1 * para2;
        }
        else
        {
          res = para1 / para2;
        }
        sprintf(buffer, "%d", res);
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
        EDIT_SetText(hItem, buffer);
        state1 = 4;
      }
      break;
      case (4):
      {
      }
      break;
      default:
        state1 = 0;
      }
    }
    break;
  // USER END
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
 *
 *       Public code
 *
 **********************************************************************
 */
/*********************************************************************
 *
 *       CreateFramewin2
 */
WM_HWIN CreateFramewin2(void);
WM_HWIN CreateFramewin2(void)
{
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}

// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
